package com.sdleyou.treepro.business.api.friend;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.UserFriendManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class UserFriendController {

    @Autowired
    private UserFriendManager userFriendManager;

    /**
     * 好友列表
     */
    @ApiVersion(1)
    @PostMapping("/{version}/friend/list")
    public ResultVO friendList(@RequestParam("user_id") String userId,
                               @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                               @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum) {
        return ResultVOUtil.success(userFriendManager.getUserFriendList(userId, pageNum, pageSize));
    }

    /**
     * 添加好友
     */
    @ApiVersion(1)
    @PostMapping("/{version}/friend/add")
    public ResultVO addFriend(@RequestParam("user_id") String userId,
                              @RequestParam("friend_id") String friendId,
                              @RequestParam("resource") String resource) {
        return ResultVOUtil.success(userFriendManager.addFriend(userId, friendId, resource));
    }

    /**
     * 附近的人
     * @param userId
     * @param distance
     * @param userLng
     * @param userLat
     * @return
     */
    @PostMapping("/{version}/nearby/list")
    public ResultVO nearBySearch(
                                @RequestParam("user_id") String userId,
                                @RequestParam(name = "distance", defaultValue = "20") double distance,
                                @RequestParam("userLng") double userLng,
                                @RequestParam("userLat") double userLat) {
        return ResultVOUtil.success(userFriendManager.getNearby(userId, userLng, userLat, distance));
    }
}
